@include('admin.public.head')

<div class="ibox-title">
    <h5>商城添加</h5>
</div>

<div class="ibox-content">
    <form  class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-3 control-label">商品名稱：</label>
            <div class="col-sm-9">
                <input type="text" name="goods_name" class="form-control"  value="{{$result->goods_name??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>


        <div class="form-group">
            <label class="col-sm-3 control-label">商品原價：</label>
            <div class="col-sm-9">
                <input  type="number" min="0" name="original_price" class="form-control"  value="{{$result->original_price??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">商品現價：</label>
            <div class="col-sm-9">
                <input  type="number" min="0" name="goods_price" class="form-control"  value="{{$result->goods_price??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">库存：</label>
            <div class="col-sm-9">
                <input  type="number" min="0" name="stock" class="form-control"  value="{{$result->stock??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">商品圖片：</label>
            <div class="col-sm-9">
                <input type="file" name="goods_img" class="form-control"  value="">
                <img src="{{$result->goods_img??''}}" width="300" height="150">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">是否上架：</label>
            <div class="col-sm-9">
                <label value="1">
                    <input type="radio" name="is_opend"  value="1" @if(isset($result->is_opend)) @if($result->is_opend == 1) checked @endif @else checked @endif>上架
                </label>
                <label value="0">
                    <input type="radio"  name="is_opend"  value="2" @if(isset($result->is_opend)) @if($result->is_opend == 2) checked @endif @endif>下架
                </label>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">使用描述説明：</label>
            <div class="col-sm-8">
                <script id="describe" name="describe" type="text/plain" style="height:300px;">{!! $result->describe??'' !!}</script>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">使用须知：</label>
            <div class="col-sm-8">
                <script id="instruction" name="instruction" type="text/plain" style="height:300px;">{!! $result->instruction??'' !!}</script>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">使用细则：</label>
            <div class="col-sm-8">
                <script id="details" name="details" type="text/plain" style="height:300px;">{!! $result->details??'' !!}</script>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <input type="hidden" name="id" value="{{$id??0}}">


        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-3">
                <button class="btn btn-primary do" type="submit">操作</button>
                <a href="/goods" class="btn btn-primary" >返回商品列表</a>
            </div>
        </div>

    </form>
</div>

<script>

    var describe = UE.getEditor('describe');
    var instruction = UE.getEditor('instruction');
    var details = UE.getEditor('details');

    $('.do').click(function(){
        var form = new FormData();

        var id = $('input[name="id"]').val();
        var goods_name = $('input[name="goods_name"]').val();
        var stock = $('input[name="stock"]').val();
        var original_price = $('input[name="original_price"]').val();
        var goods_price = $('input[name="goods_price"]').val();
        var is_opend = $('input[name="is_opend"]:checked').val();
        var goods_img = $('input[name="goods_img"]')[0].files[0];
        var class_describe = describe.getContent();
        var class_instruction = instruction.getContent();
        var class_details = details.getContent();

        form.append("goods_name", goods_name);
        form.append("stock", stock);
        form.append("original_price", original_price);
        form.append("goods_price", goods_price);

        form.append("is_opend", is_opend);
        form.append("goods_img", goods_img);
        form.append("describe", class_describe);
        form.append("instruction", class_instruction);
        form.append("details", class_details);

        form.append("id", id);

        $.ajax({
            type: 'POST',
            url: '/goods_do' ,
            dataType:"json",   //返回格式为json
            data: form ,
            processData: false,
            contentType: false,
            success:function(data){

                if(data.status == '1') {
                    var swal_json = {
                        title: data.message,
                        type: "success"
                    }

                    swal(swal_json, function (isConfirm) {
                        window.location.reload();
                    });

                }else{
                    var swal_json = {
                        title: data.message,
                        type: "error"
                    }

                    swal(swal_json, function (isConfirm) {

                    });
                }
            }
        });

        return false;
    });
</script>
